package com.woniu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.pojo.Order;
import com.woniu.pojo.Patrol;
import com.woniu.vo.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PatrolMapper extends BaseMapper<Patrol> {

    @Select("select r.name from t_road r,rl_road_patrol rl where rl.road_id = r.id and rl.patrol_id = #{id}")
    List<String> selectStreetNameByPatrolId(Long id);
    @Select("select count(*) from t_order where status = 3 and patrol_id = #{id}")
    int selectOrderSuccessById(Long id);
    @Select("select count(*) from t_order where  patrol_id = #{id}")
    int selectOrderAllById(Long id);
    @Delete("delete from rl_road_patrol where patrol_id = #{id}")
    void deleteRelationById(Long id);
    @Insert("insert into rl_road_patrol (road_id,patrol_id,create_time,update_time) values (#{roadId},#{patrolId},#{createTime},#{updateTime})")
    void insertRelation(RlRoadPatrolAddVo rlRoadPatrolAddVo);
    @Select("select r.id from t_road r,rl_road_patrol rl where rl.road_id = r.id and rl.patrol_id = #{id}")
    List<Long> selectStreetIdByPatrolId(Long id);
    @Update("update t_patrol set status = '0' where id = #{id}" )
    int updateStatusToStopById(Long id);
    @Update("update t_patrol set status = '1' where id = #{id}" )
    int updateStatusToUseById(Long id);
    IPage<Patrol> selectPages(@Param("page") Page<Patrol> page, @Param("patrolSearchVo") PatrolSearchVo patrolSearchVo);
    @Select("select count(*) from t_order where status != 3 and patrol_id = #{id}")
    int selectOrderUnusualById(Long id);
    Page<Order> selectOrderByPatrolId(@Param("page") Page<Patrol> page, @Param("id") Long id, @Param("orderPatrolSearchVo") OrderPatrolSearchVo orderPatrolSearchVo);
    @Select("select distinct r.name from t_road r,t_space s where s.id = #{spaceId} and s.road_id = r.id")
    String selectStreetNameBySpaceId(Long spaceId);
    @Select("select num from t_car where id = #{carId}")
    String selectCarNumByCarId(Long carId);
    @Select("select * from t_checking_in where patrol_id = #{id}")
    Page<CheckResVo> selectCheck(@Param("page") Page<CheckResVo> page ,@Param("id") Long id);
    @Select("select * from t_order where id = #{id}")
    Order selectOrderById(Long id);
    @Select("select u.nickname from t_car c,t_user u where c.id = #{carId} and c.user_id = u.id")
    String selectUserNameByCarId(Long carId);
    @Select("select id from t_magnet where space_id = #{id}")
    Long selectMagnetId(Long id);
    @Select("select i.uri from rl_order_image rl ,t_image i where rl.order_id = #{id} and rl.image_id = i.id")
    List<String> selectImageByOrderId(Long id);
    @Select("select id,type,day_type,hour_type,free_time,hour_time_start,hour_time_end,include_free,price,max_money " +
            "from t_charge where road_id = #{id}")
    List<ChargeReturnVo> selectChargeRulByRoadId(Long id);
    @Select("select s.road_id from t_order o, t_space s where o.space_id = s.id and o.id = #{id}")
    Long selectRoadIdByOrderId(Long id);
}
